package cn.uce.common.utils;

import org.apache.commons.beanutils.ConvertUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

/**
 * 对象属性克隆
 * Created by hg on 2018/6/7.
 */
public class BeanUtilsEx extends BeanUtils {
    private final static Logger logger = LoggerFactory.getLogger(BeanUtilsEx.class);

    static {
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        ConvertUtils.register(new DateConvert(), String.class);
    }

    public static void copyProperties(Object target, Object source) {
        // 支持对日期copy
        try {
            BeanUtils.copyProperties(source,target);
        } catch (Exception e) {
            logger.error("扩展BeanUtils.copyProperties支持data类型:", e);
        }
    }
}
